package com.wen.controller;

import com.wen.pojo.Auth;
import com.wen.pojo.Role;
import com.wen.pojo.User;
import com.wen.service.RoleService;
import com.wen.utils.PageBean;
import com.wen.utils.Result;
import dto.AuthGrandDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    //查询所有角色
    @RequestMapping("/role-list")
    public Result roleList(){
        List<Role> roles = roleService.allRoleList();
        return Result.ok(200,"查询成功",roles);
    }

    //分页查询所有角色列表
    @RequestMapping("role-page-list")
    public Result<PageBean<Role>> rolePageList(Integer pageNum, Integer pageSize, Role role){
        PageBean<Role> allRolePageList =  roleService.allRolePageList(pageNum,pageSize,role);
        return Result.ok(200,"查询成功",allRolePageList);
    }

    //添加角色role-add
    @RequestMapping("/role-add")
    public Result roldAdd(@RequestBody Role role){
        return roleService.addRole(role);
    }

    //启动，禁用角色
    @RequestMapping("/role-state-update")
    public Result roleStateUpdata(@RequestBody Role role){
        return roleService.updRoleState(role);
    }

    //删除角色
    @RequestMapping("/role-delete/{roleId}")
    public Result delRole(@PathVariable Integer roleId){
        return roleService.delRole(roleId);
    }

    //根据id回显分配菜单
    @RequestMapping("/role-auth")
    public Result roleAuth(Integer roleId){
        List<Integer> allFpListById = roleService.findAllFpListById(roleId);
        return Result.ok(200,"查询成功",allFpListById);
    }

    //根据id更新角色全西安
    @RequestMapping("/auth-grant")
    public Result authGrant (@RequestBody AuthGrandDto authGrandDto){
        return roleService.authGrant(authGrandDto);
    }

    //修改角色
    @RequestMapping("/role-update")
    public Result updRole(@RequestBody Role role){
        return roleService.updRole(role);
    }
}
